﻿using System.Windows.Markup;

namespace RSkor.Common.WinForms
{
    [ContentProperty("Rows")]
    public class TableLayoutPanel : System.Windows.Forms.TableLayoutPanel
    {
        public TableLayoutRowCollection Rows
        {
            get { return null; }
            set
            {
                if (value != null)
                {
                    for (int rowNo = 0; rowNo < value.Count; rowNo++)
                    {
                        TableRow row = value[rowNo];
                        if (row.Style != null)
                        {
                            while (this.RowStyles.Count < rowNo + 1)
                                this.RowStyles.Add(new System.Windows.Forms.RowStyle());
                            this.RowStyles[rowNo] = row.Style;
                        }
                        if (row.Cells != null)
                        {
                            int colNo = 0;
                            foreach (TableCell cell in row.Cells)
                            {
                                if (cell.Column >= 0)
                                {
                                    colNo = cell.Column;
                                }

                                if (cell.Control != null)
                                {
                                    cell.Control.Parent = this;
                                    this.SetColumn(cell.Control, colNo);
                                    this.SetColumnSpan(cell.Control, cell.ColumnSpan);
                                    this.SetRow(cell.Control, rowNo);
                                    this.SetRowSpan(cell.Control, cell.RowSpan);
                                }
                                colNo++;
                            }
                        }
                    }
                }
            }
        }

    }
}
